/*
var settingss ={
    view:{
        enable: true,
        addHoverDom: addHoverDom,
        removeHoverDom: removeHoverDom,
        selectedMulti:false
    },
    edit: {
        enable: true,
        editNameSelectAll: true,
        removeTitle: "删除",
        renameTitle: "编辑名称"
    },
    data: {
        simpleData: {
            enable: true,  //true 、 false 分别表示 使用 、 不使用 简单数据模式
            idKey: "id",   //节点数据中保存唯一标识的属性名称
            pIdKey: "pid",   //节点数据中保存其父节点唯一标识的属性名称
            rootPId: -1  //用于修正根节点父节点数据，即 pIdKey 指定的属性值
        },
        key: {
            name: "name"  //zTree 节点数据保存节点名称的属性名称  默认值："name"
        }
    },
    callback: {
        onClick:select
    }
}

function geneTypeTree(){
    $.getJSON("getTree",function(response){
        zTree = $.fn.zTree.init($("#tree"),settingss,response)
        zTree.expandAll(true)
        var node = zTree.getNodeByParam("id", "010101");
        zTree.checkNode(node, true, false);
    })
}
$(function (){
    //生成树
    geneTypeTree()
})
/!**
 * 点击节点回显数据
 *!/
function select(event,treeId,treeNode){
    console.log(treeNode.pid+","+treeNode.id+","+treeId+",id长度"+treeNode.id.length)
    var $thead_list = $('#thead_list')
    var $tbody_list = $('#tbody_list')

    if (treeNode.pid == -1){//最高级次
        var level = 2
        $thead_list.empty()
        $tbody_list.empty()
        $thead_list.append("<tr><th>部门ID</th><th>部门名称</th><th>级次</th><th>操作</th></tr>")
            $.ajax({
                url:"getTree",
                type: 'get',
                data: 'level='+level,
                    // 'id':$("input[name='Dm']").val()
                success: function (data) {
                    if (data.length != 0){
                        for (var x in data) {
                            $tbody_list.append("<tr>" +
                                "<td>"+data[x].tId+"</td>" +
                                "<td>"+data[x].name+"</td>" +
                                "<td>"+data[x].level+"</td>" +
                                "<td><a class='btn btn-xs btn-info active' id='update' href=\"#modal-container-one\" data-toggle='modal' onclick=\"getBmName('" + data[x].tId + "')\">重命名<a/>" +
                                " <a class='btn btn-xs btn-danger active' onclick=\"deleteTreeNode('"+data[x].tId+"')\">删除<a/></td>" +
                                "</tr>")
                        }
                    }

                }
            })
    }

    if (treeNode.id.length == 2){//第二级
        $thead_list.empty()
        $tbody_list.empty()
        $thead_list.append("<tr><th>项目ID</th><th>项目负责人ID</th><th>项目名称</th><th>项目级次</th><th>操作</th></tr>")
        $.ajax({
            url:"getList",
            type: 'get',
            data:'pid=' + treeNode.id,
            success: function (data) {
                var $dataLength = data.length
                if ($dataLength != 0){
                    for (var x in data) {
                        console.log(data[x].name)
                        $tbody_list.append("<tr>" +
                            "<td>"+data[x].xmId+"</td>" +
                            "<td>"+data[x].xmOwnerid+"</td>" +
                            "<td>"+data[x].treeNode.name+"</td>" +
                            "<td>"+data[x].treeNode.level+"</td>" +
                            "<td><a class='btn btn-xs btn-info active' id='update' href=\"#modal-container-two\" data-toggle='modal' onclick=\"getXmName('" + data[x].treeNode.tId + "')\">重命名<a/>" +
                            " <a class='btn btn-xs btn-danger active' onclick=\"deleteTreeNode('"+data[x].treeNode.tId+"')\">删除<a/></td>" +
                            "</tr>")
                    }
                }

            }
        })
    }

    if (treeNode.id.length == 4){//第三级次
        $thead_list.empty()
        $tbody_list.empty()
        $thead_list.append("<tr><th>项目代码</th><th>项目明细</th><th>项目有效金额</th><th>创建时间</th><th>最后修改时间</th><th>操作</th></tr>")
        $.ajax({
            url:"getProjectXmdm",
            type: 'get',
            data:'xmDm=' + treeNode.id,
            success: function (data) {
                $tbody_list.append("<tr>" +
                    "<td>"+data.xmDm+"</td>" +
                    "<td>"+data.xmDetailed+"</td>" +
                    "<td>"+data.xmJeyx+"</td>" +
                    "<td>"+data.xmTime+"</td>" +
                    "<td>"+data.xmOldtime+"</td>" +
                    "<td><a class='btn btn-xs btn-info active' id='update' href=\"#modal-container-xm\" data-toggle='modal' onclick=\"getXmUpdate('" + data.xmDm + "')\">修改<a/>" +
                    " <a class='btn btn-xs btn-danger active' onclick=\"removeXm('"+data.xmDm+"')\">删除<a/></td>" +
                    "</tr>")
            }
        })
    }

    if (treeNode.id.length >= 6){//最后级次
        if (treeNode.name == '员工信息列表'){
            var pageNo = 1
            $.ajax({
                url: 'showUsers',
                type: 'get',
                data: {
                    "name": $("input[name='userName']").val(),
                    // "isSort": isSort,
                    "pageNo":pageNo
                    // "pageSize":pageSize
                },
                dataType: 'json',
                success: function (data) {
                    var pageNo = data.userArray[1]//当前页码
                    var totalCount = data.userArray[2]//总数据量
                    var totalPage = data.userArray[3]//总页数
                    pageList(pageNo,totalCount,totalPage)
                    $thead_list.empty()
                    $tbody_list.empty()
                    $thead_list.append("<tr>" +
                        "<th>ID</th>" +
                        "<th>用户名</th>" +
                        "<th>身份证号码</th>" +
                        "<th>手机号码</th>" +
                        "<th>地址</th>" +
                        "<th>出生日期</th>" +
                        "<th>年龄</th>" +
                        "<th>操作</th>" +
                        "</tr>")
                    for (var i = 0; i < totalCount; i++) {
                        var user_list = data.userArray[0][i]//赋值每一个对象
                        //console.log(user_list['userid'])
                        $tbody_list.append("<tr>" +
                            "<td>"+user_list.userid+"</td>" +
                            "<td>"+user_list.name+"</td>" +
                            "<td>"+user_list.idcard+"</td>" +
                            "<td>"+user_list.mobiile+"</td>" +
                            "<td>"+user_list.address+"</td>" +
                            "<td>"+user_list.birtday+"</td>" +
                            "<td>"+user_list.age+"</td>" +
                            "<td><a class='btn btn-xs btn-info active' id='update' href=\"#modal-container\" data-toggle='modal' onclick=\"getUpdate('" + user_list.userid + "')\">修改<a/>" +
                            " <a class='btn btn-xs btn-danger active' onclick=\"removeUser('"+user_list.idcard+"')\">删除<a/></td>" +
                            "</tr>")
                    }
                }
            })//ajax请求

        }else{

        }

    }
}

/!*function search(){
    $.ajax({
        url:"getDm",
        type: 'get',
        data:'id=' + $("input[name='Dm']").val(),
        success: function (data) {
                    $tbody_list.append("<tr>" +
                        "<td>"+data[x].tId+"</td>" +
                        "<td>"+data[x].name+"</td>" +
                        "<td>"+data[x].level+"</td>" +
                        "<td><a class='btn btn-xs btn-info active' id='update' href=\"#modal-container-one\" data-toggle='modal' onclick=\"getBmName('" + data[x].tId + "')\">重命名<a/>" +
                        " <a class='btn btn-xs btn-danger active' onclick=\"deleteTreeNode('"+data[x].tId+"')\">删除<a/></td>" +
                        "</tr>")
            }
    })
}*!/

/!**
 * 动态获取页码
 * @param pageNo 当前页码
 * @param totalCount 总数据量
 * @param totalPage 总页数
 *!/
function pageList(pageNo,totalCount,totalPage){
    /!*
        页数的回显
     *!/
    $('#page_text').text("当前页"+pageNo+"，总页数"+totalPage+"，共"+totalCount+"条记录")
    //分页回显
    var $page_Array = new Array(totalPage)
    var $page_list = $('#page_list')
    $page_list.empty()
    //页码的回显
    for (var i = 0; i < $page_Array.length; i++) {
        var index = i + 1
        $page_list.append("<a id='index_page' href='javascript:currpage("+index+")'>"+index+"</a>")
    }
    /!*
        指定页面
     *!/
}


/!**
 *
 * @param treeId
 * @param treeNode
 *!/
function addHoverDom(treeId, treeNode) {
    var sObj = $("#" + treeNode.tId + "_span"); //获取节点信息
    if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length>0) return;

    var addStr = "<span class='button add' id='addBtn_" + treeNode.tId + "' title='add node' οnfοcus='this.blur();'></span>"; //定义添加按钮
    sObj.after(addStr); //加载添加按钮
    var btn = $("#addBtn_"+treeNode.tId);

    //绑定添加事件，并定义添加操作
    if (btn) btn.bind("click", function(){
        var zTree = $.fn.zTree.getZTreeObj("tree");
        //将新节点添加到数据库中
        var name='NewNode';
        $.post('./index.php?r=data/addtree&pid='+treeNode.id+'&name='+name,function (data) {
            var newID = data; //获取新添加的节点Id
            zTree.addNodes(treeNode, {id:newID, pId:treeNode.id, name:name}); //页面上添加节点
            var node = zTree.getNodeByParam("id", newID, null); //根据新的id找到新添加的节点
            zTree.selectNode(node); //让新添加的节点处于选中状态
        });
    });
}

function removeHoverDom(treeId, treeNode) {
    $("#addBtn_"+treeNode.tId).unbind().remove();
}


*/
